#ifndef __MPOINTS_H__
#define __MPOINTS_H__

#include <algorithm>
#include <vector>

#include "MPoint.h"

template< class T >
class MPoints
{
public:
	MPoints( const MRect& rect )
	{
		addPoint( MPoint( rect.x(), rect.y() ) );
		addPoint( MPoint( rect.x() + rect.width(), rect.y() ) );
		addPoint( MPoint( rect.x(), rect.y() + rect.height() ) );
		addPoint( MPoint( rect.x() + rect.width(), rect.y() + rect.height() ) );
	}

	~MPoints();

	void addPoint( const T& point )
	{
		_points.push_back( point );
	}
	
	void removePoint( const T& point )
	{
		_points.erase( std::find( _points.begin(), _points.end(), point ) );
	}

	T& operator []( size_t n )
	{
		return _points[ n ];
	}

	MPoints& operator + ( const MPoints& points )
	{
		std::for_each( _points.begin(), _points.end(), T::operator + );
	}

	MPoints& operator - ( const MPoints& points );
	MPoints& operator * ( const MPoints& points );
	MPoints& operator / ( const MPoints& points );
	
	MPoints& operator + ( float value );
	MPoints& operator - ( float value );
	MPoints& operator * ( float value );
	MPoints& operator / ( float value );
	
private:
	std::vector< T >	_points;
};

typedef MPoints< MPoint >		MPoints2D;

#endif